package com.qf.controller;

import com.qf.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

//@Controller
//@ResponseBody //类中所有方法都有@ResponseBody，可以将其直接写到类上
@RestController //等价于@Controller+@ResponseBody
//@RequestMapping("/user")
public class UserController3 {

//    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
//    @ResponseBody
    @GetMapping("/{id}") //等价于@RequestMapping(method = RequestMethod.GET)
    public String get(@PathVariable Integer id){
        System.out.println("查询:" + id);

        return "查询成功~~";
    }

//    @RequestMapping(method = RequestMethod.POST)
//    @ResponseBody
    @PostMapping //等价于@RequestMapping(method = RequestMethod.POST)
    public String add(@RequestBody User user){
        System.out.println("新增:" + user);

        return "新增成功~~";
    }

//    @RequestMapping(method = RequestMethod.PUT)
//    @ResponseBody
    @PutMapping  //等价于@RequestMapping(method = RequestMethod.PUT)
    public String update(@RequestBody User user){
        System.out.println("更新:" + user);

        return "更新成功~~";
    }

//    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
//    @ResponseBody
    @DeleteMapping("/{id}")   //等价于@RequestMapping(method = RequestMethod.DELETE)
    public String delete(@PathVariable Integer id){
        System.out.println("删除:" + id);
        return "删除成功~~";
    }
}
